<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#id").click(function(){
			$(this).val("");
		});
		
		$("#login_btn").click(function() {
			var id = $("#member_id").val();
			var password = $("#password").val();
		    if(id==null ||id==""){
			      alert("id 를 입력하세요!");	
			    }
		    else if(password==null ||password==""){
		    	alert("password 를 입력하세요!");
		    }		    
			$.ajax({
				type : "POST",
				url : "factory.do",
				data : "command=login&member_id=" + id + "&password=" + password,
				dataType : "json", // json으로 datatype을 명시 
				success : function(jsonData) { // data 변수로 json 입력된다.	
					if(jsonData.lmvo==null){
				    	alert("해당하는 회원정보가 없습니다!");
				    	$("#member_id").val("");
				    	$("#password").val("");
				    	return;
				    }
					else if(jsonData.lmvo.grade=="ceo"){
				    	location.href="factory.do?command=goCeo";
				    }
					else{
				    	location.href="factory.do?command=goOperator";
				    }
				}// success
			});//ajax 	  
		});//click
		$("#logout_btn").click(function() {
			var flag = window.confirm("로그아웃 하시겠습니까?");
			if(flag){
			$.ajax({
				type : "POST",
				url : "factory.do",
				data : "command=logout",
				success : function() {			
				    location.href="factory.do?command=mainView";
				}
			});//ajax
			}
		});
	});
</script>
</head>
<body>
<center>
<c:choose>
<c:when test="${sessionScope.login==null}">
<img src="/BF_MES/img/loginbefo.png" style="vertical-align:middle;" width="30" height="30" vspace="30">
<input type="hidden" name="command" value="login"> 
<img src="/BF_MES/img/id.jpg" style="vertical-align:middle;"> <input type="text" id="member_id"> 
<img src="/BF_MES/img/password.jpg" style="vertical-align:middle;">  <input type="password"  id="password" > 
<img src="/BF_MES/img/login_re.gif" style="vertical-align:middle;" id="login_btn">
</c:when>
<c:otherwise>
<img src="/BF_MES/img/loginaft.png" style="vertical-align:middle;" width="30" height="30" vspace="30">
  ${sessionScope.login.member_id} 님 로그인
<img src="/BF_MES/img/btn_logout.gif" style="vertical-align:middle;" id="logout_btn">
</c:otherwise>
</c:choose>
</center>
</body>
</html>